package com.pdwl.cashoutpay.service.imp;

import com.pdwl.cashoutpay.dao.MerchantMapper;
import com.pdwl.cashoutpay.dao.MerchantResMapper;
import com.pdwl.cashoutpay.entity.Merchant;
import com.pdwl.cashoutpay.entity.res.MerchantRes;
import com.pdwl.cashoutpay.service.MerchantRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MerchantRegisterServiceImp implements MerchantRegisterService {

    @Autowired
    private MerchantMapper merchantMapper;

    @Autowired
    private MerchantResMapper merchantResMapper;

    @Override
    public void add(Merchant merchant) {
        merchantMapper.insert(merchant);
    }


    @Override
    public Merchant update(Merchant merchant) {
        Merchant entity = new Merchant();
        int result = merchantMapper.updateByOutMerchantCode(merchant);
        if (result == 1) {
            entity = merchantMapper.selectByOutMechantCode(merchant.getOutmerchantcode());
        }
        return entity;
    }

    @Override
    public Merchant updateAll(Merchant merchant) {
        Merchant entity = new Merchant();
        int result = merchantMapper.updateByPrimaryKey(merchant);
        if (result == 1) {
            entity = merchantMapper.selectByOutMechantCode(merchant.getOutmerchantcode());
        }
        return entity;
    }

    @Override
    public Merchant query(String accNo) {
        Merchant merchant = merchantMapper.selectByAccNo(accNo);
        return merchant;
    }

    @Override
    public MerchantRes queryByMerchCode(String merchCode) {
        MerchantRes merchantRes = merchantResMapper.selectByMerchCode(merchCode);
        return merchantRes;
    }

    @Override
    public MerchantRes queryByCertNoAndPMercId(String certNo, String pMercId) {
        MerchantRes merchant = merchantResMapper.selectByCertNoAndPMercId(certNo, pMercId);
        return merchant;
    }

    @Override
    public Merchant queryByOutMerchCode(String outMerchCode) {

        return merchantMapper.selectByOutMechantCode(outMerchCode);
    }

    @Override
    public Merchant queryBySubMerchCode(String subMerchCode) {
        return merchantMapper.selectBySubMerchCode(subMerchCode);
    }

    @Override
    public Merchant queryByPMercId(String pMercId) {
        return merchantMapper.selectByPMercId(pMercId);
    }

    @Override
    public MerchantRes queryByOutMerchCode1(String outMerchCode) {

        return merchantResMapper.selectByOutMechantCode(outMerchCode);
    }


}
